package com.designoutput.ui
{
	import com.designoutput.enum.ElementType;
	import com.designoutput.enum.ToolType;
	import com.designoutput.icon.*;
	import com.designoutput.manager.ResourceManager;
	import com.designoutput.ui.controls.*;
	import com.designoutput.ui.newControls.Box;
	import com.designoutput.ui.options.*;
	import com.designoutput.ui.toolGroup.*;
	import com.designoutput.utils.Globals;
	
	import flash.display.Sprite;

	public class LeftToolBar extends Box
	{
		public var p:DesignoutputCard;

		public var toolsHolder:BasicToolGroup; // contains normal bars, like Rectange/Text etc.
		public var _optionsHolder:Sprite; // contains operation bars when click different tool bar
		public var _layerSizeGroup:LayerSizeGroup; // contains the Portrait/Landscape and Width/Height of card

		public var selection:ToolButton;
		public var trash:ToolButton;
		public var frontLayer:Radiobutton;
		public var backLayer:Radiobutton;

		public var showSardLayersHolder:Boolean = false;
		
		//options for editing element
		public var baseOption:BaseOption;
		public var textOption:TextOption;
		public var rectangleOption:RectangleOption;
		public var roundRectangleOption:RoundRectangleOption;
		public var ellipseOption:EllipseOption;
		public var starOption:StarOption;
		public var polyLineOption:PolyLineOption;
		public var imageOption:ImageOption;
		public var lineOption:LineOption;

		
		override protected function initialize():void
		{
			p = Globals.designoutputCard;
			
			super.initialize();
			
			setTitle(ResourceManager.getValue("rm_tools"));
			
			width = 140;
			height = 620;
			
			baseOption = new BaseOption(p);
			textOption = new TextOption(p);
			rectangleOption = new RectangleOption(p);
			roundRectangleOption = new RoundRectangleOption(p);
			ellipseOption = new EllipseOption(p);
			polyLineOption = new PolyLineOption(p);
			starOption = new StarOption(p);
			imageOption = new ImageOption(p);
			lineOption = new LineOption(p);

			toolsHolder = new BasicToolGroup(this);
			addChild(toolsHolder);
			_layerSizeGroup = new LayerSizeGroup();
			addChild(_layerSizeGroup);
			
			/************************************* Basic tools ***************************************/
			toolsHolder.x = 0;

			/********************************** SetSings/Options ************************************/

			/*optionsHolder*/

			/**********************************Portrait/Landscape and Width/Height of card**********************************/
			_layerSizeGroup.x = 0;

			/*****************************************************************************************/

			_optionsHolder = new Sprite;
			_optionsHolder.x = 10;
			addChild(_optionsHolder);

			rePositionHolders();
		}

		/**
		 * @param showSardLayersHolder - A boolean value,if <em>true</em> the Front&Back layer radio buttons show.
		 * if <em>false</em> disappear.
		 *
		 */
		private function rePositionHolders(showSardLayersHolder:Boolean = false):void
		{
			toolsHolder.y = 5;
			_optionsHolder.y = 160;
			_layerSizeGroup.y = 525;
		}

		/**
		 * Called by CommandManager. Restore the tool mode
		 * */
		public function restore():void
		{
			toolsHolder.setDefaultTool();
		}


		/**
		 * When end user chose associated tool, show tool options on this panel.
		 * @param type
		 *
		 */
		public function addOption(type:String = null):void
		{
			if (_optionsHolder.numChildren > 0)
			{
				_optionsHolder.removeChildAt(0);
			}
			switch (type)
			{
				case ToolType.BaseElement:
					_optionsHolder.addChild(baseOption);
					break;
				case ToolType.Rectangle:
					_optionsHolder.addChild(rectangleOption);
					break;
				case ToolType.RoundRectangle:
					_optionsHolder.addChild(roundRectangleOption);
					break;
				case ToolType.Ellipse:
					_optionsHolder.addChild(ellipseOption);
					break;
				case ToolType.StarPolygon:
					_optionsHolder.addChild(starOption);
					break;
				case ToolType.FreeFormLine:
					_optionsHolder.addChild(polyLineOption);
					break;
				case ToolType.Line:
					_optionsHolder.addChild(lineOption);
					break;
				case ToolType.Image:
					_optionsHolder.addChild(imageOption);
					break;
				case ToolType.Text:
					_optionsHolder.addChild(textOption);
					break;
				default:
					break;
			}
		}

		/**
		 * Called when different element editing
		 * @param elementType:ElementType string
		 * @param element: such as the BaseElement, TextElement, Star Element etc...
		 *
		 */
		public function optionSetValues(elementType:String = null, element:* = null,bothShirtAndSleeves:Boolean = false,forSleeveElements:Boolean = false):void
		{
			switch (elementType)
			{
				case ElementType.BaseElement:
					addOption(ToolType.BaseElement);
					baseOption.updateBaseInfor(element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.RectangleElement:
					addOption(ToolType.Rectangle);
					rectangleOption.updateOptions(elementType, element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.RoundRectangleElement:
					addOption(ToolType.RoundRectangle);
					roundRectangleOption.updateOptions(elementType, element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.EllipseElement:
					addOption(ToolType.Ellipse);
					ellipseOption.updateOptions(elementType, element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.StarElement:
					addOption(ToolType.StarPolygon);
					starOption.updateOptions(elementType, element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.PolyLineElement:
					addOption(ToolType.FreeFormLine);
					polyLineOption.updateOptions(elementType, element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.LineElement:
					addOption(ToolType.Line);
					lineOption.updateOptions(element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.TextElement:
					addOption(ToolType.Text);
					textOption.updateOptions(element,bothShirtAndSleeves,forSleeveElements);
					break;
				case ElementType.ImageElement:
					addOption(ToolType.Image);
					imageOption.updateOptions(elementType,element,bothShirtAndSleeves,forSleeveElements);
					break;
				default:
					addOption();
					break;

			}
		}

		public function constrainSetMarked(flag:Boolean):void
		{
			toolsHolder.constrainSetMarked(flag);
		}
	}
}